package com.tsinghuabigdata.edu.ddmath.fragment;

import android.os.Bundle;

import roboguice.fragment.RoboFragment;

public class MyBaseFragment extends RoboFragment {
    private static final String TAG = "MyBaseFragment";
    private IFragmentStackManage fragmentSM;

    private void init() {
        if (fragmentSM == null) {
            fragmentSM = (IFragmentStackManage) getActivity();
        }
    }

    public void goFragment(RoboFragment fragment) {
        init();
        fragmentSM.addStack(fragment, fragmentSM.getCurrentStackIndex());
        fragmentSM.showTopfragment(fragmentSM.getCurrentStackIndex());
    }

    public void goFragment(RoboFragment fragment, Bundle bundle) {
        init();
        fragment.setArguments(bundle);
        fragmentSM.addStack(fragment, fragmentSM.getCurrentStackIndex());
        fragmentSM.showTopfragment(fragmentSM.getCurrentStackIndex());
    }

    public void finish() {
        init();
        fragmentSM.removeFromStack(fragmentSM.getCurrentStackIndex());
        fragmentSM.showTopfragment(fragmentSM.getCurrentStackIndex());
    }

    public IFragmentStackManage getFragmentSM() {
        return fragmentSM;
    }

    public void setFragmentSM(IFragmentStackManage fragmentSM) {
        this.fragmentSM = fragmentSM;
    }
}
